<template>
   <div class="common-layout">
    <el-container>
      <el-header>
        <el-row :gutter="20">
    <el-col :span="4"><img src="../assets/logo.png" alt="" class="logo"></el-col>
    <el-col :span="16"><h2>后台管理系统</h2></el-col>
    <el-col :span="4" class="col-btn"><el-button @click="delToken">退出登录</el-button></el-col>
    </el-row>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
       active-text-color="#ffd04b"
        background-color="#545c64"
        class="el-menu-vertical-demo"
        :default-active="active"
        text-color="#fff"
        router
      >
      <!-- default-active="active" 要加这个属性，是为了浏览器刷新后，仍然可以定位到之前选中的路由 -->
        <el-menu-item v-for="item in list" :key="item.path" :index="item.path">
          <span>{{item.meta.title}}</span>
        </el-menu-item>
      </el-menu>
        </el-aside>
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useRoute, useRouter } from 'vue-router';

export default defineComponent({
  name: 'HomeView',
  setup(){
    const route=useRoute();
    const router =useRouter();
    const list=router.getRoutes().filter(v=>v.meta.isShow)
    const delToken=()=>{
      localStorage.removeItem('token');
      router.push('/login');
    }
    return{list,active:route.path,delToken}
  }
  
});
</script>
<style>
.common-layout{
  height: 100%;
}
.el-header{
   height: 80px;
   background-color: #666;
}
.logo{
  height: 80px;
}
h2{
  text-align: center;
  height: 80px;
  line-height: 80px;
}
.col-btn{
  height: 80px;
  line-height: 80px;
  color:#fff;
}
.el-aside{
  background-color: #666;
  /*减号前后必须有空格，否则不生效*/
  height: calc(100vh - 80px);
}
.el-menu{
  height: calc(100vh - 80px);
}
</style>
